//package com.example.event_resource_java.starinside.shiro;
//
//import com.baomidou.mybatisplus.core.conditions.Wrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.example.event_resource_java.authority.server.UserServer;
//import com.example.event_resource_java.commons.domain.UserDO;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.crypto.hash.Sha256Hash;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.apache.shiro.util.ByteSource;
//
//import java.util.Collection;
//import java.util.HashSet;
//import java.util.Set;
//
///**
// * <pre>
// * </pre>
// *
// * <small> 2018年3月23日 | Aron</small>
// */
//@Slf4j
//@AllArgsConstructor
//public class SysUserAuthorizingRealm extends AuthorizingRealm {
//
//    private final UserServer userService;
//
//    @Override
//    public boolean supports(AuthenticationToken token) {
//        return token instanceof UsernamePasswordToken;
//    }
//
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//        SimpleAuthorizationInfo authz = new SimpleAuthorizationInfo();
//        Collection realm = principals.fromRealm(getName());
//        if(realm.isEmpty()){
//            return authz;
//        }
//
//
//        HashSet<String> roles = new HashSet<>();
//        authz.setRoles(roles);
//        return authz;
//    }
//
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
//
//        if(log.isDebugEnabled()){
//            log.debug("token:" + token.getCredentials() + ", " + token.getPrincipal());
//        }
//
//        String username = (String) token.getPrincipal();
//        Wrapper<UserDO> wrapper = new QueryWrapper<UserDO>().eq("username",username);
//
//        // 查询用户信息
//        UserDO user = userService.getOne(wrapper);
//        // 账号不存在
//        if (user == null) {
//            throw new UnknownAccountException("账号或密码不正确");
//        }
//        // 账号锁定
//        if (user.getStatus() == 0) {
//            throw new LockedAccountException("账号已被锁定,请联系管理员");
//        }
//
//        ByteSource salt = new Sha256Hash(user.getSalt());
//
//        return new SimpleAuthenticationInfo(user, user.getPassword(), salt, getName());
//    }
//
//}
